// 笔试强训day30:相差不超过k的最多数

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 0, left = 0, right = 1;
    for(right = 1; right < n; right++)
    {
        if(a[right] - a[left] > k)
        {
            ans = max(ans, right - left);
            while(a[right] - a[left] > k) left++;
        }
    }
    if(right == n)
    {
        ans = max(ans, right - left);
    }
    cout << ans << endl;
}